using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;
using DIS_DAO.DAO;
using DIS_DAO.Helpers;

namespace DIS_DAO.DTO
{
	/// <summary>
	/// Data transfer object which is associated with WeeklyReport table in database
	/// </summary>
	public class WeeklyReportDTO
	{
		public int ID { get; set; }
		public int IDChemistWareHouse { get; set; }
		public DateTime StartDate { get; set; }
		public DateTime EndDate { get; set; }
		public string Note { get; set; }
        public ChemistWareHouseDTO ChemistWareHouse { get; set; }

		public static WeeklyReportDTO Translate(DataRow row)
		{
			var dto = new WeeklyReportDTO
			{
				ID = int.Parse(row["ID"].ToString()),
				IDChemistWareHouse = int.Parse(row["IDChemistWareHouse"].ToString()),
				StartDate = DateTime.Parse(row["StartDate"].ToString()),
				EndDate = DateTime.Parse(row["EndDate"].ToString()),
				Note = row["Note"].ToString(),
			};

            var rpt = new ChemistWareHouseDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(dto.IDChemistWareHouse);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    dto.ChemistWareHouse = ChemistWareHouseDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }

			return dto;
		}
	}
}